cmake_minimum_required(VERSION 3.20)

set(CMAKE_C_COMPILER emcc)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_COMPILER em++)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/bin/")
set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(PLATFORM Web)

project(webg)

message("${CMAKE_C_COMPILER}")
message("${CMAKE_CXX_COMPILER}")
message("${CMAKE_TOOLCHAIN_FILE}")

add_compile_options(-L./lib/ -I./include -I/usr/lib/emscript/include )

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -s ASSERTIONS=1 -s WASM=1 -s GL_ENABLE_GET_PROC_ADDRESS=1 -s USE_GLFW=3 -sASYNCIFY -DPLATFORM_WEB --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/include/minshell.html --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/resource -sALLOW_MEMORY_GROWTH -sABORTING_MALLOC=0")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}  -s ASSERTIONS=1 -s WASM=1 -s GL_ENABLE_GET_PROC_ADDRESS=1 -s USE_GLFW=3 -sASYNCIFY -DPLATFORM_WEB --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/include/minshell.html --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/resource -sALLOW_MEMORY_GROWTH -sABORTING_MALLOC=0")


include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/")
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib/")

link_libraries(wraylib)

aux_source_directory(./src SRC)
add_executable("game.html" ${SRC})

if(RUNTEST STREQUAL "YES")
    aux_source_directory(./test TESTSRC)
    foreach(TSRC ${TESTSRC})
        get_filename_component(FNAME ${TSRC} NAME_WLE)
        add_executable("test${FNAME}.html" ${TSRC})
    endforeach()
endif()


